package com.sz.web.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.util.StringUtils;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class LoginController {

    @RequestMapping("/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model, HttpSession session){
        System.out.println(username);
        System.out.println(password);
        if(!StringUtils.isEmpty(username)&&password.equals("123456")){
            session.setAttribute("loginUser",username);
            return "redirect:/main.html";//重定向页面
        }else {
            model.addAttribute("msg","用户名或者密码错误");
            return "index";
        }
    }

    @RequestMapping("/out")
    public String signOut(HttpSession session){
        session.invalidate();
        return "redirect:/index.html";
    }
}
